﻿#include <qg/qg.h>

using namespace tpl;

int main(void)
{
	k_mesg("TEXTURE MOTION TEST\n");

	qgDevice* dev = qgDevice::New("", 640, 480, QGSDF_MSAA | QGSDF_LAYOUT | QGSDF_AUTO);

	if (dev)
	{
		dev->Mount(QG_WORK_PATH);

		qgStub* stub = dev->GetStub();
		qgFreeType* font = qgFreeType::New();

		// flag: QGTEXF_PRELOAD for preload all texture data to memory
		// no flag will do streaming from disk
		qgTexture* tex = dev->CreateTexture("/texture/z.hxp", QGTEXF_PRELOAD);
		qgITextureMotion* tm = tex->GetMotion();
		tm->TurnLoop(true);

		//
		while (dev->Run())
		{
			float adv = stub->GetAdvance();

			tm->MotionUpdate(adv);

			dev->Enter();

			Rect rt(Point(20, 20), Point(tex->GetWidth(), tex->GetHeight()));
			dev->DrawRect(rt, tpl::ColorValues::White, tex);

			font->WriteFormat(5, 5, 0, "[%.2f] %.2f/%.2f", stub->GetRunFps(), tm->GetAdvance(), tm->GetLength());

			dev->Leave();
			dev->Flush();
		}

		font->Unload();
		dev->Unload();
	}

	return 0;
}
